fix(cli): stop reprinting streamed assistant text after 'Done' in non-compact text mode#3273
fix(cli): stop reprinting streamed assistant text after 'Done' in non-compact text mode#3273nankingjing wants to merge 2 commits into
Conversation
Co-Authored-By: Claude <noreply@anthropic.com>
|
Pushed one follow-up on top of #3273: extended the same newline-before-spinner.finish guard to the auto-compaction retry success path. That branch also runs with New head: |
|
Nice fix! The root cause is clear: |
Summary
Fixes #3258.
In non-compact text mode (and the interactive REPL),
LiveCli::run_turnprints the entire assistant response twice:
emit_output = true, soAnthropicRuntimeClient::consume_streamalready streams and renders every text delta to the terminal live
(
main.rs,ContentBlockDelta::TextDelta/MessageStop).spinner.finish("✨ Done")it then callsprintln!("{final_text}"), reprinting the whole message that was just streamed.The reprint was originally added because
Spinner::finishrunsMoveToColumn(0)+Clear(ClearType::CurrentLine)and would otherwise erasethe last streamed line (the streamed tail has no trailing newline). Reprinting
the full text "fixed" the erased line but duplicated everything above it.
Fix
Protect only the last streamed line instead of reprinting the whole message:
println!()beforespinner.finishso the line-clear lands on a fresh empty line rather than thelast content line.
println!("{final_text}")reprint.final_textis still computed and used to decide whether a newline is needed,so the empty-response path (tool-only turns) is unchanged. Compact/JSON paths
use
emit_output = falseand print the message exactly once — they areuntouched.
Scope
rust/crates/rusty-claude-cli/src/main.rs(LiveCli::run_turn), +9 -4.Verification
Verified by reading and tracing the streaming path (
consume_streamwrites eachtext delta live when
emit_outputis true;prepare_turn_runtime(true)is usedby
run_turn, while the compact/JSON paths useprepare_turn_runtime(false))and by inspecting
Spinner::finish's line-clear behavior. Not compiled orexecuted in this environment (full Rust workspace build not available here).
The change is a local reordering plus removal of one
println!;final_textremains used, so no unused-variable warning is introduced.